<template>
	<view>
		<s-pull-scroll ref="pullScroll" :pullDown="pullDown" :pullUp="loadData" :back-top="true">
			<view class="content">
				<view class="list">
					<view class="item" v-for="item in dataList" :key="item.id">
						<view class="title" v-if="item.station">
							{{item.station.name}}
						</view>
						<view class="items-center justify-between">
							<view class="left">
								<view class="text">
									桩号：{{item.num}}
								</view>
								<view class="text" v-if="item.status == '0'">
									预约将于{{item.endDate}}失效
								</view>
								<view class="text" v-else>
									已失效
								</view>
							</view>
							<view class="right" v-if="item.status == '0'" @click="handleQx(item.num)">
								取消预约
							</view>
						</view>
					</view>
				</view>
			</view>
		</s-pull-scroll>
		<mix-loading v-if="isLoading"></mix-loading>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList:[]
			};
		},
		onLoad() {
			this.refresh();
		},
		methods:{
			handleQx(num){
				uni.showModal({
					content:'是否取消预约',
					success:(e)=>{
						if(e.confirm){
							this.cancellationFn(num)
						}
					}
				})
			},
			pullDown(pullScroll) {
				setTimeout(() => {
					this.loadData(pullScroll);
				}, 200);
			},
			async loadData(pullScroll) {
				const data = {
					uid: uni.getStorageSync('uid'),
					pageNo: pullScroll.page,
					pageSize: '10'
				};
				if (pullScroll.page == 1) this.dataList = [];
				const res = await this.$request('recharge/record-yy', data, { showLoading: true });
				if (res.result == 0) {
					this.dataList = this.dataList.concat(res.data.list);
					pullScroll.endByPage(Math.ceil(res.data.count / 10), res.data.list);
				} else {
					this.$util.msg(res.resultNote);
				}
			},
			async cancellationFn(num){
				let res = await this.$request('recharge/cancel-yy',{
					uid:uni.getStorageSync('uid'),
					num
				},{ showLoading: true })
				if(res.result == '0'){
					this.refresh()
				}
			}
		},
	}
</script>

<style lang="scss" scoped> 
	.content{
		padding: 30rpx;
		.list{
			.item{
				background: #FFFFFF;
				border-radius: 20rpx;
				padding: 30rpx;
				margin-bottom: 20rpx;
				.title{
					font-size: 34rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333333;
					margin-bottom: 20rpx;
				}
				.left{
					.text{
						font-size: 24rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #666666;
						line-height: 36rpx;
					}
				}
				.right{
					width: 150rpx;
					height: 60rpx;
					background: #FFF;
					border: 2rpx solid $uni-color-bg;
					border-radius: 30rpx;
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: $uni-color-bg;
					line-height: 60rpx;
					text-align: center;
				}
			}
		}
	}
</style>
